var qjmobileParamMap,
	ycmobileParamMap,
	gzmobileParamMap,
	hbmobileParamMap,
	spmobileParamMap,
	flagyc,
	flagqj,
	flaggz,
	flaghb,
	flagsp;
$(function(){
	leftmenu("#leftmenu","#wrap");
	//获取个性签名和图片
	getBaseMessage();
	//获取消息列表
	getMessage();
	$("#ycwork").on("tap",function(){
		//location.href="/mobile/mywork/ycwork.html?canReturn=Y";
		gotoLocation("/mobile/mywork/ycwork.html","");
	});
	$("#qjwork").on("tap",function(){
		if(flagqj==1){
			/*
			var map="?empl_rcd="+qjmobileParamMap.empl_rcd+"&endDate="+qjmobileParamMap.endDate
				+"&pin_take_num="+qjmobileParamMap.pin_take_num
				+"&startDate="+qjmobileParamMap.startDate
				+"&yearMonth="+qjmobileParamMap.startDate.substr(0,7)+"";
			*/
			var map="empl_rcd="+qjmobileParamMap.empl_rcd+"&endDate="+qjmobileParamMap.endDate
				+"&pin_take_num="+qjmobileParamMap.pin_take_num
				+"&startDate="+qjmobileParamMap.startDate
				+"&yearMonth="+qjmobileParamMap.startDate.substr(0,7)+"";
			sendMessage("ABSE");
			setTimeout(function(){
				//location.href="/mobile/mywork/qjdwork.html"+map+"&canReturn=Y";
				gotoLocation("/mobile/mywork/qjdwork.html",map);
			},1000);
		}else{
			//location.href="/mobile/mywork/qjwork.html?canReturn=Y";
			gotoLocation("/mobile/mywork/qjwork.html","");
		}
	});
	$("#mysalary").on("tap",function(){
		if(flaggz==1){
//			var map="?emplid="+gzmobileParamMap.emplid+"&year="+gzmobileParamMap.year+"";
			sendMessage("GPPY");
			setTimeout(function(){
//				location.href="/mobile/mysalary/gzd-chaxun.html"+map+"&canReturn=Y";
				//location.href="/mobile/mysalary/gzd-chaxun.html";
				gotoLocation("/mobile/mysalary/gzd-chaxun.html","");
			},1000);
		}else{
			//location.href="/mobile/mysalary/gzd-chaxun.html?canReturn=Y";
			gotoLocation("/mobile/mysalary/gzd-chaxun.html","");
		}
	});
	$("#myydhb").on("tap",function(){
		if(flaghb==1){
			//var map="?report_date="+hbmobileParamMap.report_date+"";
			sendMessage("EPRA");
			setTimeout(function(){
				toReport(hbmobileParamMap.report_date);
			},1000);
			//location.href="/mobile/myreport/wdydbg-chakan.html"+map+"&canReturn=Y";
		}else{
			//location.href="/mobile/myreport/wdydbg-chakan.html?canReturn=Y";
			toReport("");
		}
	});
	$("#mysp").on("tap",function(){
		//location.href="/mobile/underlingReport/xslb.html?canReturn=Y";
		gotoLocation("/mobile/underlingReport/xslb.html","");
	});
	
	$("#myfund").on("tap",function(){
		//location.href="/mobile/myfund/mszq.html";
		gotoLocation("/mobile/myfund/mszq.html","");
	});
});

//获取个性签名和图片
function getBaseMessage(){
	var flag = true;
	if(document.cookie.length > 0){
		var cookieArray = document.cookie.split(";");
		for(var k = 0;k < cookieArray.length;k ++){
			var cookieInfo = cookieArray[k].split("=");
			if(cookieInfo[0] == "indexOfUserInfo"){
				var ss = unescape(cookieInfo[1]).split(";");
				for(var i = 0;i < ss.length;i ++){
					var ii = ss[i].split("=");
					if(ii[0]=="userNameCn"){
						flag = false;
						$("#userName").html(ii[1]);
					}
					if(ii[0]=="userRemark"){
						$("#remark").html(ii[1]);
					}
					if(ii[0]=="imageUrl"){
						if(ii[1]==""){
							$("#headphoto").attr("src",mpsurl+"/mobile/photo/photo.png");
						}else{
							$("#headphoto").attr("src",mpsurl+"/mobile/createPicture/writePicture.do");
						}
					}
				}
				
			}
		}
	}
	if(flag){
		$.ajax({
			type:"post",
			url:mpsurl+"/mobile/base/selectUserByEmpId.do",
			dateType:"json",
			data:{method:"selectUserByEmpId"},
			success:function(data){
				data = eval("("+data+")");
				if(data.resultCode=="500600"){	
					var userDTO = data.userDTO;
					var nameCn = userDTO.emplName;
					var remark = userDTO.remark;
					var phone = userDTO.phone;
					var imgurl = userDTO.imageUrl;
					$("#userName").html(nameCn);
					$("#remark").html(remark);
					if(imgurl==""){
						$("#headphoto").attr("src",mpsurl+"/mobile/photo/photo.png");
					}else{
						$("#headphoto").attr("src",mpsurl+"/mobile/createPicture/writePicture.do");
					}
					var info = "userRemark="+remark+";userNameCn="+nameCn+";userPhone="+phone+";imageUrl="+imgurl;
					document.cookie = "indexOfUserInfo="+escape(info);
				}else{
					if(data.resultCode=="500702" || data.resultCode=="500802" || data.resultCode=="500803"){
					checkLogin(data.resultCode,"/mobile/index.html","");
					}
				}
			},
			error: function (XMLHttpRequest, textStatus, errorThrown) {
					//alert(errorThrown);
			}
		});
	}
}

//获取消息列表
function getMessage(){
	$.ajax({
		type:"post",
		url:mpsurl+"/mobile/messageList/queryMessageList.do",
		dateType:"json",
		success:function(data){
			var obj=eval("("+data+")");
			if(obj.value.length!=0){
				for(var i=0;i<obj.value.length;i++){
					var Valuedate=obj.value[i].paicOutDate.substr(0,10);//日期截取
					if(obj.value[i].paicMessageType=="ABSE"&&obj.value[i].paicOutFlag==1){//请假单
							$("#Myqjd").text(obj.value[i].messageData);
							$("#MyqjdData").text("更新时间:"+Valuedate);
							$("#ABSE").attr("value",obj.value[i].ransactionNbr);
							flagqj=obj.value[i].paicOutFlag;//是否已读
							qjmobileParamMap=obj.value[i].mobileParamMap//得到需要传输的数据
					}else if(obj.value[i].paicMessageType=="GPPY"&&obj.value[i].paicOutFlag==1){//工资单
		                    $("#MyMoney").text(obj.value[i].messageData);
							$("#MyMoneyData").text("更新时间:"+Valuedate);
							$("#GPPY").attr("value",obj.value[i].ransactionNbr);
							flaggz=obj.value[i].paicOutFlag;//是否已读
							gzmobileParamMap=obj.value[i].mobileParamMap;//得到需要传输的数据
					}else if(obj.value[i].paicMessageType=="ABSR"){//异常考勤
		                     $("#YCContent").text(obj.value[i].messageData);
		 					 $("#YCDate").text("更新时间:"+Valuedate);
		 					 $("#ABSR").attr("value",obj.value[i].ransactionNbr);
		 					 flagyc=obj.value[i].paicOutFlag;//是否已读
		 					 ycmobileParamMap=obj.value[i].mobileParamMap;//得到需要传输的数据
					}else if(obj.value[i].paicMessageType=="EPRA"&&obj.value[i].paicOutFlag==1){//提交月度汇报
		                     $("#MyHB").text(obj.value[i].messageData);
		 					 $("#MyHBData").text("更新时间:"+Valuedate);
		 					 $("#EPRA").attr("value",obj.value[i].ransactionNbr);
		 					 flaghb=obj.value[i].paicOutFlag;//是否已读
		 					 hbmobileParamMap=obj.value[i].mobileParamMap;//得到需要传输的数据
					}else if(obj.value[i].paicMessageType=="EPEM"){//主考核人审批月度汇报 
		                    $("#MyHBSP").text(obj.value[i].messageData);
							//$("#MyHBSPData").text("更新时间:"+Valuedate);
							$("#EPEM").attr("value",obj.value[i].ransactionNbr);
							$("#MyHBSPData").text("更新时间:"+Valuedate);
							flagsp=obj.value[i].paicOutFlag;//是否已读
							spmobileParamMap=obj.value[i].mobileParamMap;//得到需要传输的数据
					}
				}
			}
		},
		error: function (XMLHttpRequest, textStatus, errorThrown) {
			//alert(errorThrown);
		}
	 });
}

function sendMessage(id){
	var ransactionNbr = $("#"+id).val();
	if(ransactionNbr!=""){
		$.ajax({
			type:"post",
			url:mpsurl+"/mobile/messageList/updateMessageList.do",
			dateType:"json",
			data:{ransactionNbr:ransactionNbr},
			success:function(data){
			},
			error: function (XMLHttpRequest, textStatus, errorThrown) {
			
			}
		});
	}
}